Skip to content

Conversation

@petrochenkov
Copy link
Contributor

@petrochenkov petrochenkov commented Jan 23, 2026

This is a continuation of #150741 and #150982 based on the ideas from #151491 (comment).

Before this PR Macros20NormalizedIdent was used as a key in various "identifier -> its resolution" maps in rustc_resolve.
Macros20NormalizedIdent is a newtype around Ident in which SyntaxContext (packed inside Span) is guaranteed to be normalized using normalize_to_macros_2_0.
This type is also used in a number of functions looking up identifiers in those maps.
Macros20NormalizedIdent still contains span locations, which are useless and ignored during hash map lookups and comparisons due to Ident's special PartialEq and Hash impls.

This PR replaces Macros20NormalizedIdent with a new type called IdentKey, which contains only a symbol and a normalized unpacked syntax context. (E.g. IdentKey == Macros20NormalizedIdent minus span locations.)
So we avoid keeping additional data and doing some syntax context packing/unpacking.

Along with IdentKey you can often see orig_ident_span: Span being passed around.
This is an unnormalized span of the original Ident from which IdentKey was obtained.
It is not used in map keys, but it is used in a number of other scenarios:

  • diagnostics
  • edition checks
  • allow_unstable checks

This is because normalize_to_macros_2_0 normalization is lossy and the normalized spans / syntax contexts no longer contain parts of macro backtraces, while the original span contains everything.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 23, 2026
@petrochenkov
Copy link
Contributor Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 23, 2026
rust-bors bot pushed a commit that referenced this pull request Jan 23, 2026
resolve: Replace `Macros20NormalizedIdent` with `IdentKey`
@petrochenkov petrochenkov removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 23, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 23, 2026

☀️ Try build successful (CI)
Build commit: 0b62e28 (0b62e28b1ffadafe2f62aaba7d06486bcdb96f83, parent: d222ddc4d90743dfc1e53b610be8fc9d95893d2c)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0b62e28): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.2% [0.1%, 0.3%] 2
Improvements ✅
(primary)
-0.2% [-0.3%, -0.2%] 21
Improvements ✅
(secondary)
-0.5% [-1.4%, -0.1%] 24
All ❌✅ (primary) -0.2% [-0.3%, -0.2%] 21

Max RSS (memory usage)

Results (primary -1.7%, secondary -1.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.6% [1.7%, 3.6%] 3
Improvements ✅
(primary)
-1.7% [-1.8%, -1.7%] 2
Improvements ✅
(secondary)
-3.2% [-6.4%, -2.3%] 5
All ❌✅ (primary) -1.7% [-1.8%, -1.7%] 2

Cycles

Results (primary 0.7%, secondary 5.8%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.7% [0.7%, 0.7%] 1
Regressions ❌
(secondary)
5.8% [4.9%, 6.8%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.7% [0.7%, 0.7%] 1

Binary size

Results (secondary -0.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.0% [-0.0%, -0.0%] 9
All ❌✅ (primary) - - 0

Bootstrap: 470.684s -> 470.503s (-0.04%)
Artifact size: 383.48 MiB -> 383.42 MiB (-0.02%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jan 23, 2026
@petrochenkov petrochenkov added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 23, 2026
@petrochenkov petrochenkov marked this pull request as ready for review January 23, 2026 22:30
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 23, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 23, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 23, 2026

r? @fee1-dead

rustbot has assigned @fee1-dead.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@petrochenkov
Copy link
Contributor Author

r? @nnethercote

@rustbot rustbot assigned nnethercote and unassigned fee1-dead Jan 23, 2026
@petrochenkov
Copy link
Contributor Author

(I also want to try passing the ident: IdentKey, orig_ident_span: Span pair to resolve_ident_in_scope_set, but it may have some negative performance effects, so I'll try it separately.)

Copy link
Contributor

@nnethercote nnethercote left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable. A couple of minor comments.

View changes since this review


/// Combination of a symbol and its macros 2.0 normalized hygiene context.
/// Used as a key in all kinds of name containers, including modules (as a part of slightly larger
/// `BindingKey`) and preludes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like some of the details from the PR description to be added here. E.g. that this is like Macros20NormalizedIdent but without the spans, and it exists as an optimization to avoid useless span operations when doing hash/eq.

Also, the detail about orig_ident_span often being passed around (and it being unnormalized) would be useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E.g. that this is like Macros20NormalizedIdent but without the spans

Macros20NormalizedIdent is no longer used and removed in this PR, so we cannot make this comparison anymore :)

mod hygiene {
use rustc_span::SyntaxContext;

/// An newtype around `SyntaxContext` that can only keep contexts produced by
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// An newtype around `SyntaxContext` that can only keep contexts produced by
/// A newtype around `SyntaxContext` that can only keep contexts produced by

}

/// Combination of a symbol and its macros 2.0 normalized hygiene context.
/// Used as a key in all kinds of name containers, including modules (as a part of slightly larger
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"All kinds" is ambiguous. Does it mean "every kind" or "many kinds"?

@nnethercote
Copy link
Contributor

@rustbot author

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 27, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 27, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 27, 2026
@rust-bors

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Jan 27, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@petrochenkov
Copy link
Contributor Author

Updated.
@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 27, 2026
@nnethercote
Copy link
Contributor

Thanks.

@bors r+

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 28, 2026

📌 Commit 5726e37 has been approved by nnethercote

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 28, 2026
@rust-bors

This comment has been minimized.

@rust-bors rust-bors bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 28, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 28, 2026

☀️ Test successful - CI
Approved by: nnethercote
Duration: 3h 8m 16s
Pushing de6d33c to main...

@rust-bors rust-bors bot merged commit de6d33c into rust-lang:main Jan 28, 2026
12 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Jan 28, 2026
@github-actions
Copy link
Contributor

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 1e5065a (parent) -> de6d33c (this PR)

Test differences

Show 44 test diffs

44 doctest diffs were found. These are ignored, as they are noisy.

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard de6d33c033441c5880b863f94d7a3ec8cad141bd --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. pr-check-2: 2313.7s -> 3198.9s (+38.3%)
  2. dist-armv7-linux: 5289.9s -> 6534.2s (+23.5%)
  3. pr-check-1: 1644.9s -> 2000.1s (+21.6%)
  4. dist-apple-various: 4444.9s -> 3499.1s (-21.3%)
  5. aarch64-gnu-debug: 3957.1s -> 4668.1s (+18.0%)
  6. x86_64-gnu-llvm-20: 4125.3s -> 4838.0s (+17.3%)
  7. x86_64-gnu-tools: 3336.1s -> 3911.3s (+17.2%)
  8. x86_64-rust-for-linux: 2695.3s -> 3092.8s (+14.7%)
  9. x86_64-gnu-llvm-21-3: 6049.7s -> 6877.0s (+13.7%)
  10. test-various: 6751.5s -> 7618.8s (+12.8%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (de6d33c): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.0% [0.0%, 0.0%] 3
Improvements ✅
(primary)
-0.3% [-0.5%, -0.1%] 69
Improvements ✅
(secondary)
-0.5% [-1.7%, -0.0%] 37
All ❌✅ (primary) -0.3% [-0.5%, -0.1%] 69

Max RSS (memory usage)

Results (primary -2.6%, secondary -0.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.3% [1.3%, 6.8%] 8
Improvements ✅
(primary)
-2.6% [-4.5%, -1.5%] 3
Improvements ✅
(secondary)
-3.1% [-5.4%, -0.8%] 11
All ❌✅ (primary) -2.6% [-4.5%, -1.5%] 3

Cycles

Results (primary -10.0%, secondary -2.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
5.5% [4.8%, 6.2%] 2
Improvements ✅
(primary)
-10.0% [-15.4%, -3.5%] 10
Improvements ✅
(secondary)
-5.1% [-6.5%, -2.6%] 5
All ❌✅ (primary) -10.0% [-15.4%, -3.5%] 10

Binary size

Results (primary -0.0%, secondary -0.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.0% [-0.0%, -0.0%] 4
Improvements ✅
(secondary)
-0.0% [-0.0%, -0.0%] 10
All ❌✅ (primary) -0.0% [-0.0%, -0.0%] 4

Bootstrap: 474.687s -> 474.844s (0.03%)
Artifact size: 397.87 MiB -> 397.84 MiB (-0.01%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants